USE [Example.Repository]
GO

IF NOT EXISTS (SELECT * FROM sys.tables WHERE [name] = N'cacheability' AND [type] = N'U')
	BEGIN
	CREATE TABLE [dbo].[cacheability]
	(
		[identity] INT NOT NULL
	)
	END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE [name] = N'cacheability.primarykey')
	BEGIN
	ALTER TABLE [dbo].[cacheability] WITH NOCHECK ADD CONSTRAINT [cacheability.primarykey] PRIMARY KEY CLUSTERED ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'cacheability' AND c.[name] = N'value'
)
	BEGIN
	ALTER TABLE [dbo].[cacheability] ADD [value] VARCHAR(20) NULL
	END
GO

IF EXISTS (SELECT * FROM [dbo].[cacheability] WHERE [value] IS NULL)
	BEGIN
	UPDATE [dbo].[cacheability] SET [value] = CAST([identity] AS VARCHAR(20)) WHERE [value] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'cacheability' AND c.[name] = N'value' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[cacheability] ALTER COLUMN [value] VARCHAR(20) NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.indexes AS i
	INNER JOIN sys.tables AS t ON t.[object_id] = i.[object_id]
	WHERE t.[name] = N'cacheability' AND i.[name] = N'cacheability.index.value'
)
	BEGIN
	CREATE UNIQUE INDEX [cacheability.index.value] ON [dbo].[cacheability] ([value])
	END
GO

IF NOT EXISTS (SELECT * FROM [dbo].[cacheability] WHERE [identity] = 1)
	BEGIN
	INSERT INTO [dbo].[cacheability] ([identity], [value]) VALUES (1, 'NoCache')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[cacheability] WHERE [identity] = 2)
	BEGIN
	INSERT INTO [dbo].[cacheability] ([identity], [value]) VALUES (2, 'Private')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[cacheability] WHERE [identity] = 3)
	BEGIN
	INSERT INTO [dbo].[cacheability] ([identity], [value]) VALUES (3, 'Server')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[cacheability] WHERE [identity] = 4)
	BEGIN
	INSERT INTO [dbo].[cacheability] ([identity], [value]) VALUES (4, 'Public')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[cacheability] WHERE [identity] = 5)
	BEGIN
	INSERT INTO [dbo].[cacheability] ([identity], [value]) VALUES (5, 'ServerAndPrivate')
	END
GO

IF NOT EXISTS (SELECT * FROM sys.tables WHERE [name] = N'status' AND [type] = N'U')
	BEGIN
	CREATE TABLE [dbo].[status]
	(
		[identity] INT NOT NULL
	)
	END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE [name] = N'status.primarykey')
	BEGIN
	ALTER TABLE [dbo].[status] WITH NOCHECK ADD CONSTRAINT [status.primarykey] PRIMARY KEY CLUSTERED ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'status' AND c.[name] = N'value'
)
	BEGIN
	ALTER TABLE [dbo].[status] ADD [value] VARCHAR(50) NULL
	END
GO

IF EXISTS (SELECT * FROM [dbo].[status] WHERE [value] IS NULL)
	BEGIN
	UPDATE [dbo].[status] SET [value] = CAST([identity] AS VARCHAR(50)) WHERE [value] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'status' AND c.[name] = N'value' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[status] ALTER COLUMN [value] VARCHAR(50) NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.indexes AS i
	INNER JOIN sys.tables AS t ON t.[object_id] = i.[object_id]
	WHERE t.[name] = N'status' AND i.[name] = N'status.index.value'
)
	BEGIN
	CREATE UNIQUE INDEX [status.index.value] ON [dbo].[status] ([value])
	END
GO

IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 100)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (100, 'Continue')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 101)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (101, 'Switching Protocols')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 200)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (200, 'OK')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 201)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (201, 'Created')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 202)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (202, 'Accepted')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 203)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (203, 'Non-Authoritative Information')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 204)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (204, 'No Content')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 205)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (205, 'Reset Content')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 206)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (206, 'Partial Content')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 300)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (300, 'Multiple Choices')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 301)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (301, 'Moved Permanently')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 302)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (302, 'Found')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 303)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (303, 'See Other')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 304)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (304, 'Not Modified')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 305)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (305, 'Use Proxy')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 306)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (306, '(Unused)')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 307)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (307, 'Temporary Redirect')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 400)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (400, 'Bad Request')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 401)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (401, 'Unauthorized')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 402)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (402, 'Payment Required')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 403)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (403, 'Forbidden')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 404)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (404, 'Not Found')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 405)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (405, 'Method Not Allowed')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 406)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (406, 'Not Acceptable')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 407)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (407, 'Proxy Authentication Required')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 408)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (408, 'Request Timeout')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 409)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (409, 'Conflict')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 410)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (410, 'Gone')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 411)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (411, 'Length Required')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 412)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (412, 'Precondition Failed')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 413)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (413, 'Request Entity Too Large')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 414)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (414, 'Request-URI Too Long')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 415)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (415, 'Unsupported Media Type')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 416)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (416, 'Requested Range Not Satisfiable')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 417)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (417, 'Expectation Failed')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 500)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (500, 'Internal Server Error')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 501)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (501, 'Not Implemented')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 502)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (502, 'Bad Gateway')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 503)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (503, 'Service Unavailable')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 504)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (504, 'Gateway Timeout')
	END
GO
IF NOT EXISTS (SELECT * FROM [dbo].[status] WHERE [identity] = 505)
	BEGIN
	INSERT INTO [dbo].[status] ([identity], [value]) VALUES (505, 'HTTP Version Not Supported')
	END
GO

IF NOT EXISTS (SELECT * FROM sys.tables WHERE [name] = N'assembly' AND [type] = N'U')
	BEGIN
	CREATE TABLE [dbo].[assembly]
	(
		[identity] INT IDENTITY(1,1) NOT NULL
	)
	END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE [name] = N'assembly.primarykey')
	BEGIN
	ALTER TABLE [dbo].[assembly] WITH NOCHECK ADD CONSTRAINT [assembly.primarykey] PRIMARY KEY CLUSTERED ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'assembly' AND c.[name] = N'name'
)
	BEGIN
	ALTER TABLE [dbo].[assembly] ADD [name] VARCHAR(260) NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.indexes AS i
	INNER JOIN sys.tables AS t ON t.[object_id] = i.[object_id]
	WHERE t.[name] = N'assembly' AND i.[name] = N'assembly.index.name'
)
	BEGIN
	CREATE UNIQUE INDEX [assembly.index.name] ON [dbo].[assembly] ([name])
	END
GO

IF NOT EXISTS (SELECT * FROM sys.tables WHERE [name] = N'type' AND [type] = N'U')
	BEGIN
	CREATE TABLE [dbo].[type]
	(
		[identity] INT IDENTITY(1,1) NOT NULL
	)
	END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE [name] = N'type.primarykey')
	BEGIN
	ALTER TABLE [dbo].[type] WITH NOCHECK ADD CONSTRAINT [type.primarykey] PRIMARY KEY CLUSTERED ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'type' AND c.[name] = N'assembly'
)
	BEGIN
	ALTER TABLE [dbo].[type] ADD [assembly] INT NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.foreign_keys AS f
	INNER JOIN sys.tables AS t ON t.[object_id]=f.[parent_object_id]
	WHERE t.[name]=N'type' AND f.[name]=N'type.foreignkey.assembly'
)
	BEGIN
	ALTER TABLE [dbo].[type]
	ADD CONSTRAINT [type.foreignkey.assembly]
	FOREIGN KEY ([assembly])
	REFERENCES [dbo].[assembly] ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'type' AND c.[name] = N'name'
)
	BEGIN
	ALTER TABLE [dbo].[type] ADD [name] VARCHAR(260) NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.indexes AS i
	INNER JOIN sys.tables AS t ON t.[object_id] = i.[object_id]
	WHERE t.[name] = N'type' AND i.[name] = N'type.index.name'
)
	BEGIN
	CREATE UNIQUE INDEX [type.index.name] ON [dbo].[type] ([assembly], [name])
	END
GO

IF NOT EXISTS (SELECT * FROM sys.tables WHERE [name] = N'object' AND [type] = N'U')
	BEGIN
	CREATE TABLE [dbo].[object]
	(
		[identity] INT IDENTITY(1,1) NOT NULL
	)
	END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE [name] = N'object.primarykey')
	BEGIN
	ALTER TABLE [dbo].[object] WITH NOCHECK ADD CONSTRAINT [object.primarykey] PRIMARY KEY CLUSTERED ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'token'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [token] UNIQUEIDENTIFIER NULL CONSTRAINT [object.default.token] DEFAULT (NEWSEQUENTIALID())
	END
GO

IF EXISTS (SELECT * FROM [dbo].[object] WHERE [token] IS NULL)
	BEGIN
	UPDATE [dbo].[object] SET [token] = NEWID() WHERE [token] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'token' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[object] ALTER COLUMN [token] UNIQUEIDENTIFIER NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.indexes AS i
	INNER JOIN sys.tables AS t ON t.[object_id] = i.[object_id]
	WHERE t.[name] = N'object' AND i.[name] = N'object.index.token'
)
	BEGIN
	CREATE UNIQUE INDEX [object.index.token] ON [dbo].[object] ([token])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'urn'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [urn] VARCHAR(260) NULL
	END
GO

IF EXISTS (SELECT * FROM [dbo].[object] WHERE [urn] IS NULL)
	BEGIN
	UPDATE [dbo].[object] SET [urn] = 'urn://token/' + CAST([token] AS VARCHAR(260)) WHERE [urn] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'urn' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[object] ALTER COLUMN [urn] VARCHAR(260) NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.indexes AS i
	INNER JOIN sys.tables AS t ON t.[object_id] = i.[object_id]
	WHERE t.[name] = N'object' AND i.[name] = N'object.index.urn'
)
	BEGIN
	CREATE UNIQUE INDEX [object.index.urn] ON [dbo].[object] ([urn])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'created'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [created] DATETIME NULL CONSTRAINT [object.default.created] DEFAULT (GETDATE())
	END
GO

IF EXISTS (SELECT * FROM [dbo].[object] WHERE [created] IS NULL)
	BEGIN
	UPDATE [dbo].[object] SET [created] = GETDATE() WHERE [created] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'created' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[object] ALTER COLUMN [created] DATETIME NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'modified'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [modified] DATETIME NULL CONSTRAINT [object.default.modified] DEFAULT (GETDATE())
	END
GO

IF EXISTS (SELECT * FROM [dbo].[object] WHERE [modified] IS NULL)
	BEGIN
	UPDATE [dbo].[object] SET [modified] = GETDATE() WHERE [modified] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'modified' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[object] ALTER COLUMN [modified] DATETIME NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'status'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [status] INT NULL CONSTRAINT [object.default.status] DEFAULT (200)
	END
GO

IF EXISTS (SELECT * FROM [dbo].[object] WHERE [status] IS NULL)
	BEGIN
	UPDATE [dbo].[object] SET [status] = 200 WHERE [status] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'status' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[object] ALTER COLUMN [status] INT NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.foreign_keys AS f
	INNER JOIN sys.tables AS t ON t.[object_id]=f.[parent_object_id]
	WHERE t.[name]=N'object' AND f.[name]=N'object.foreignkey.status'
)
	BEGIN
	ALTER TABLE [dbo].[object]
	ADD CONSTRAINT [object.foreignkey.status]
	FOREIGN KEY ([status])
	REFERENCES [dbo].[status] ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'cacheability'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [cacheability] INT NULL CONSTRAINT [object.default.cacheability] DEFAULT (3)
	END
GO

IF EXISTS (SELECT * FROM [dbo].[object] WHERE [cacheability] IS NULL)
	BEGIN
	UPDATE [dbo].[object] SET [cacheability] = 3 WHERE [cacheability] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'cacheability' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[object] ALTER COLUMN [cacheability] INT NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.foreign_keys AS f
	INNER JOIN sys.tables AS t ON t.[object_id]=f.[parent_object_id]
	WHERE t.[name]=N'object' AND f.[name]=N'object.foreignkey.cacheability'
)
	BEGIN
	ALTER TABLE [dbo].[object]
	ADD CONSTRAINT [object.foreignkey.cacheability]
	FOREIGN KEY ([cacheability])
	REFERENCES [dbo].[cacheability] ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'etag'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [etag] CHAR(24) NULL
	END
GO

IF EXISTS (SELECT * FROM [dbo].[object] WHERE [etag] IS NULL)
	BEGIN
	UPDATE [dbo].[object] SET [etag] = '' WHERE [etag] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'etag' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[object] ALTER COLUMN [etag] CHAR(24) NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'expires'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [expires] VARCHAR(50) NULL
	END
GO

IF EXISTS (SELECT * FROM [dbo].[object] WHERE [expires] IS NULL)
	BEGIN
	UPDATE [dbo].[object] SET [expires] = '' WHERE [expires] IS NULL
	END
GO

IF EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'expires' AND [is_nullable] = 1
)
	BEGIN
	ALTER TABLE [dbo].[object] ALTER COLUMN [expires] VARCHAR(50) NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'type'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [type] INT NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.foreign_keys AS f
	INNER JOIN sys.tables AS t ON t.[object_id]=f.[parent_object_id]
	WHERE t.[name]=N'object' AND f.[name]=N'object.foreignkey.type'
)
	BEGIN
	ALTER TABLE [dbo].[object]
	ADD CONSTRAINT [object.foreignkey.type]
	FOREIGN KEY ([type])
	REFERENCES [dbo].[type] ([identity])
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.columns AS c
	INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
	WHERE t.[name] = N'object' AND c.[name] = N'xml'
)
	BEGIN
	ALTER TABLE [dbo].[object] ADD [xml] XML NOT NULL
	END
GO

IF NOT EXISTS
(
	SELECT * FROM sys.indexes AS i
	INNER JOIN sys.tables AS t ON t.[object_id] = i.[object_id]
	WHERE t.[name] = N'object' AND i.[name] = N'object.index.xml'
)
	BEGIN
	CREATE PRIMARY XML INDEX [object.index.xml] ON [object]([xml])
	END
GO